(ns leiningen.new.compojure-misty
  (:use [leiningen.new.templates :only [renderer name-to-path ->files year]]
        [leinjacker.utils :only [lein-generation]]))

(defn check-lein-version []
  (if (< (lein-generation) 2)
    (throw (new Exception "Leiningen v2 is required..."))))

(defn compojure-misty
  "Create a new Compojure project"
  [name]
  (check-lein-version)
  (let [data {:name      name
              :sanitized (name-to-path name)
              :year      (year)}
        render-fn (renderer "compojure-misty")
        render #(render-fn % data)
        raw #(render-fn %)]
    (println "Generating a Misty's new Compojure project named" (str name "..."))
    (->files data
             [".gitignore" (raw ".gitignore")]
             ["project.clj" (render "project.clj")]
             ["README.md" (render "README.md")]
             ["resources/{{sanitized}}/views/templates/home.html" (raw "home.html")]
             "resources/public/js"
             "resources/public/img"
             ["resources/public/css/screen.css" (raw "screen.css")]
             ["src/{{sanitized}}/models/db.clj" (render "db.clj")]
             ["src/{{sanitized}}/views/layout.clj" (render "layout.clj")]
             ["src/{{sanitized}}/routes/home.clj" (render "home.clj")]
             ["src/{{sanitized}}/handler.clj" (render "handler.clj")]
             ["src/{{sanitized}}/main.clj" (render "main.clj")]
             ["src/{{sanitized}}/util.clj" (render "util.clj")]
             ["test/{{sanitized}}/test/handler.clj" (render "handler_test.clj")]
             "logs"
             )))
